package com.huiyun.project.im.common.auth;

import com.huiyun.project.common.core.constant.SecurityConstants;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.io.IOException;

/**
 * 标记开放平台的接口
 */
public class GatewayFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper((HttpServletRequest) request) {
            /**
             * @param name
             * @return
             */
            @Override
            public String getHeader(String name) {
                String superHeader = super.getHeader(name);
                if (SecurityConstants.FROM.equals(name)) {
                    return "N";
                }
                return superHeader;
            }
        };
        chain.doFilter(requestWrapper, response);
    }

    @Override
    public void destroy() {
    }
}